<div class="wmm-module">
    <div class="layui-form-item">
        <form id="search-form" class="layui-form" action="javascript:;">
            <div class="layui-inline">
                <input type="text" name="alias" autocomplete="off" lay-verify="required" placeholder="别名"
                    class="layui-input">
            </div>
            <div class="layui-inline">
                <button type="submit"  class="layui-btn layui-btn-normal layui-btn-sm datatable-search"><i class="layui-icon layui-icon-search search-icon"></i>
                    查询</button>
            </div>
            <div class="layui-inline">
            <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="renders.box(null,true)">添加参数</button>
            </div>
        </form>
    </div>

    <div>
        <div id="tb-sys-table-head" lay-filter="tb-sys-table-head">
        </div>
    </div>
</div>



<template id="tmp-param-form">
    <div style="padding:10px">
        <form class="layui-form" lay-filter="param-form" action="javascript:;">
            <input type="hidden" value="" name="id" />

            <div class="layui-form-item">
                <label class="layui-form-label">编号<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="alias" autocomplete="off" lay-verify="required" placeholder="请输入别名"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">作者<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="author" placeholder="请输入作者名" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">本地存放Java路径<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="locationPath" lay-verify="required" placeholder="请填写本地存放Java路径" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">统一package<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="unitePackage" lay-verify="required" value="com.wmeimob.fastboot" placeholder="请填写package(例子：com.wmeimob.fastboot)" readonly autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目名称<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="projectName" lay-verify="required" placeholder="请填写项目名称(使用例子(linde)：com.wmeimob.fastboot.linde)" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">entity/entity.dto层<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="entityPackage" lay-verify="required" value="entity" placeholder="请填写实体层package,使用例子(entity/entity.dto):com.wmeimob.fastboot.linde.entity" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">mapper层<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="mapperPackage" lay-verify="required" value="mapper" placeholder="请填写mapper层,使用例子(mapper):com.wmeimob.fastboot.linde.mapper" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">service层<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="servicePackage" lay-verify="required" value="service" placeholder="请填写service层，如上" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">controller层<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="controllerPackage" lay-verify="required" value="controller" placeholder="请填写controller层,如上" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">html路径<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="htmlPath" lay-verify="required" placeholder="请填写html页面路径" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">版本信息<span class="required-star">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="copyright" lay-verify="required" placeholder="请填写版本信息" value="version 1.0" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn lay-submit layui-btn-normal" lay-submit lay-filter="resource">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</template>



<script>

    new Wmm({
        vars: {
            table: {},
            appList: undefined,
            reqUrl: "/sysbeetleparams/"
        },

        imports: ["form","api","datatable","req","sysTools"],
        listener: function () {

            fb.form.on('submit(resource)', function (data) {
                var dataObject = data.field;
                console.log("========dataObject=============:"+JSON.stringify(dataObject))
                if (dataObject.id) {
                    //update
                    // fb.api.resource.update(dataObject, function () {
                    //     layer.closeAll();
                    //     layer.msg("改好了");
                    //     vars.table.flush(true);
                    // });
                    req.put(vars.reqUrl,dataObject,function(data){
                        console.log("======进入成功======");
                        console.log("data:"+JSON.stringify(data));
                        if(data.code == 0){
                            layer.closeAll();
                            layer.msg("修改成功",{icon:6});
                            vars.table.flush();
                        }
                    })
                    return;
                }
                //insert
                console.log("=========dataObject========="+dataObject);
                req.post(vars.reqUrl,dataObject,function(data){
                    console.log("======进入成功======");
                    console.log("data:"+JSON.stringify(data));
                    if(data.code == 0){
                        layer.closeAll();
                        layer.msg("添加成功",{icon:6});
                        vars.table.flush();
                    }
                })
            });
        },
        requests: {
            init:function(){
                req.get(vars.reqUrl+"init",function(data){
                    console.log("======进入成功======");
                    console.log("data:"+JSON.stringify(data));
                    if(data.code == 0){
                        layer.msg("初始化成功",{icon:6});
                        vars.table.flush();
                    }
                })
            }
        },
        renders: {
            box: function (data, isCreate) {
                layer.open({
                    type: 1,
                    title: (isCreate ? "添加" : "修改") + "参数",
                    content: document.querySelector("#tmp-param-form").innerHTML,
                    area: ['550px', '760px'],
                    success: function () {
                        if (!isCreate) {
                            //表单初始赋值
                            fb.form.val('param-form', data)
                        }
                        fb.form.render();
                    }
                });
            },
            render: function () {
                vars.table = new DataTable({
                    el: "tb-sys-table-head",
                    formEl: "search-form",
                    url: vars.reqUrl,
                    multiple:true,
                    defines: [
                        {
                            head: "id",
                            prop: "id",
                        }, {
                            head: "别名",
                            prop: "alias",
                        }, {
                            head: "作者",
                            prop: "author",
                            wordBreak:true
                        },
                        {
                            head: "本地存放路径",
                            prop: "locationPath",
                        },
                        {
                            head: "统一package",
                            prop: "unitePackage",
                            wordBreak:true
                        },
                        {
                            head: "项目名称",
                            prop: "projectName",
                        },
                        {
                            head: "Entity层",
                            prop: "entityPackage",
                        },
                        {
                            head: "Mapper层",
                            prop: "mapperPackage",
                        },
                        {
                            head: "Service层",
                            prop: "servicePackage",
                        },
                        {
                            head: "Controller层",
                            prop: "controllerPackage",
                        },
                        {
                            head: "Html路径",
                            prop: "htmlPath",
                        },
                        {
                            head: "版权信息",
                            prop: "copyright",
                        },
                        {
                            head: "创建时间",
                            prop: "gmt_create",
                            type: "datetime"
                        },
                    ],
                    handles: [
                        {
                            edit: function (data) {
                                return renders.box(data, false);
                            }
                        },
                        {
                            del: {
                                tip: "确定要删除吗？",
                                do: function (data) {
                                    req.delete(vars.reqUrl+data.id,function(data){
                                        console.log("======进入成功======");
                                        console.log("data:"+JSON.stringify(data));
                                        if(data.code == 0){
                                            layer.msg("删除成功",{icon:6});
                                            vars.table.flush();
                                        }
                                    })
                                }
                            }
                        },

                    ],
                });

            },
        },

    });



</script>